// this sets the background color of the master UIView (when there are no windows/tab groups on it)

Ti.App.Properties.setString('Operator', 'admin');
Ti.App.Properties.setString('chanlesign', '1');
Ti.App.Properties.setString('ComCode', '000000');

Ti.Database.install('database/sls.dB', 'sls');

var tGlobalInput = require('GlobalInput');
var dB = require('untils/DB');
var exeSQL = require('untils/ExeSQL');
var pubFun = require('untils/PubFun');
var riskTable = require('suggest/RiskTable');
var riskFilter = require('suggest/RiskFilter');
var riskBaseData = require('suggest/RiskBaseData');
var profitCaculator = require('corecenter/ProfitCaculator');
//测试用
var ShowProfit = require('showProfit');
//测试结束用

Titanium.UI.setBackgroundImage('images/Default.png');
var win = Ti.UI.createWindow({
	backgroundColor : 'transparent'
});

var contNo = '0e261552-ce15-4030-a53d-675e706dcb8c';
// var mainPolNo = Ti.Platform.createUUID();
var mainPolNo = '27098C5F-0DB1-40D0-8D03-C1660DF7DB85';
var mainRiskPolNo = mainPolNo;
var subRiskPolNo = Ti.Platform.createUUID();
var appntNo = 'bfce5bba-9078-4515-86ce-dccfab4806af';
var insuredNo = 'bfce5bba-9078-4515-86ce-dccfab4806af';
Ti.API.info('ContNo:' + contNo);
Ti.API.info('MainPolNo:' + mainPolNo);

// TODO 主险代码
var mainRiskCode = '00111100';

//测试用
var testRiskData = new riskBaseData(mainRiskCode, contNo, mainPolNo, appntNo, insuredNo);
testRiskData.init();
var mRiskTable = new riskTable(contNo, mainPolNo, testRiskData.getBaseRiskData(), mainRiskCode, '');
mRiskTable.initRiskTableUI();

win.add(mRiskTable.getRiskTable());

// Create a Button.
var aButton = Ti.UI.createButton({
	title : '完成',
	height : 30,
	width : 100,
	top : 70,
	left : 180
});
aButton.addEventListener('click', function(e) {
	mRiskTable.checkRule(errorCallBack, errorCallBack, succedCallBack);
});

function errorCallBack(msgArr) {
	var msg = '';
	for (var i = 0; i < msgArr.length; i++) {
		msg += (msgArr[i] + '\r\n');
	}
	alert(msg);
}

function succedCallBack() {

}

// Add to the parent view.
win.add(aButton);

// Create a Button.
var bButton = Ti.UI.createButton({
	title : '收益',
	height : 30,
	width : 100,
	top : 70,
	right : 180
});

// Listen for click events.
bButton.addEventListener('click', function() {

	var mProfitCaculator = new profitCaculator(mainPolNo);
	var createObject = new Object();
	//1.计算收益表，2计算收益文档，3.计算受益图
	var type = '1';
	if (type == '1') {
		createObject = {
			data : mProfitCaculator.toProfitTableHTML()
		}
	} else if (type == '2') {
		createObject = {
			data : mProfitCaculator.toProfitDocHTML()
		}
	} else if (type == '3') {
		createObject = {
			url : 'sugfile/index.htm',
			data : mProfitCaculator.toProfitChart()
		}
	}

	var profitwin = ShowProfit.create(createObject);

	profitwin.open();

});

// Add to the parent view.
win.add(bButton);

win.open();
